<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\AgentLabel;
use Illuminate\Http\Request;

class AgentLabelController extends Controller
{
    public function store(Request $request)
    {
        return $this->response->created(null, AgentLabel::query()->create($request->only(['name'])));
    }

    public function update(Request $request, $id)
    {
        $agentLabel = AgentLabel::query()->findOrFail($id)->update($request->only(['name']));

        return $this->response->created(null, $agentLabel);
    }

    public function list(Request $request)
    {
        return $this->response->array(
            AgentLabel::query()
                ->withCount(['agents'])
                ->paginate());
    }

    public function delete($id)
    {
        $agent = AgentLabel::query()->findOrFail($id);
        $agent->delete();

        return $this->response->noContent();
    }
}
